//
//  SiXCTextStorage.m
//  scheme-indent-xcplugin
//
//  Created by Ende on 10/12/29.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "SiXCTextStorage.h"
#import "SiTools.h"

@implementation XCTextStorage (SiPlugin)

- (NSString *)substringOfItem:(XCSourceModelItem *)item {
	NSRange range = [item range];
	CFStringRef str = CFAttributedStringGetString((CFAttributedStringRef)self);
	CFStringRef str2 = CFStringCreateWithSubstring(kCFAllocatorDefault, str, CFRangeMake(range.location, range.length));
	return [(id)str2 autorelease];
}

- (BOOL)isItemInLetVarInit:(XCSourceModelItem *)item {
	//	(let ((name1 init)
	//		  |<-
	//		  (name2 init2))
	//	  body ...)
	
	static NSArray *lets = nil;
	if (!lets) lets = [[NSArray alloc] initWithObjects: @"let", @"let*", @"letrec", nil];
	
	if (item) {
		XCSourceModelItem *let_exp = [item parent];
		if (let_exp) {
			NSArray *children = [let_exp children];
			if (1 < [children count]) {
				if ([[children objectAtIndex: 1] isEqual: item]) {
					XCSourceModelItem *let_sym = [children objectAtIndex: 0];
					if (let_sym && [lets containsString: [self substringOfItem: let_sym]]) {
						return YES;
					}
				}
			}
		}
	}
	return NO;
}

- (BOOL)__getUsesTabs {
	//if ([[self language] isEqualToString: @"my.lang.scheme"]) return NO;
	return [self __getUsesTabs];
}

- (NSInteger)__getIndentWidth {
	//if ([[self language] isEqualToString: @"my.lang.scheme"]) return 2;
	return [self __getIndentWidth];
}

- (NSInteger)__getTabWidth {
	//if ([[self language] isEqualToString: @"my.lang.scheme"]) return 2;
	return [self __getTabWidth];
}

@end
